package com.atguigu.lease.common.minio;

import io.minio.MinioClient;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * ClassName: MinioConfiguration
 * Package: com.atguigu.lease.common.minio
 *
 * @Create 2025/10/30 15:32
 * @Author 阿瓒
 * @Version 1.0
 * Description: 创建minioClint 对象
 */
@EnableConfigurationProperties(MinioProperties.class)
@Configuration
public class MinioConfiguration {

    @Autowired
    private MinioProperties minioProperties;

    @Bean
    public MinioClient minioClient(){
        //1. 配置参数直接写死(硬编码)
            //application.yml 文件中声明
            //利用springBoot批量读取注解 @ConfigurationProperties(prefix = "前缀")
        //2. 我们不一定必须将配置参数写到配置类中!(配置类和配置参数没有分离)
        //      看源码的思维,将配置参数专门写了一个配置类xxx. properties
        //      我们只需要栽培之类重获取xxx. properties对象,调用方法获取参数
        MinioClient minioClient = MinioClient.builder()
                .endpoint(minioProperties.getEndpoint())
                .credentials(minioProperties.getUsername(), minioProperties.getPassword())
                .build();
        return minioClient;
    }
}
